﻿@model cloudscribe.Core.IdentityServerIntegration.Models.ConsentViewModel
@using cloudscribe.Core.IdentityServerIntegration
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<CloudscribeIds4Resources> sr
@{
    var format = sr["{0} <small>is requesting your permission</small>"];
    var messageHtml = string.Format(format, Model.ClientName);

}

<div class="page-consent">
    <div class="row page-header">
        <div class="col-sm-10">
            @if (Model.ClientLogoUrl != null)
            {
                <div class="client-logo"><img src="@Model.ClientLogoUrl"></div>
            }
            <h1>
                @Html.Raw(messageHtml)
            </h1>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-8">
            @Html.Partial("_ValidationSummary")

            <form asp-action="Index" class="consent-form" data-submit-once="true">
                <input type="hidden" asp-for="ReturnUrl" />

                <div>@sr["Uncheck the permissions you do not wish to grant."]</div>

                @if (Model.IdentityScopes.Any())
                {
                    <div class="panel panel-default consent-buttons">
                        <div class="panel-heading">
                            <span class="glyphicon glyphicon-user"></span>
                            @sr["Personal Information"]
                        </div>
                        <ul class="list-group">
                            @foreach (var scope in Model.IdentityScopes)
                            {
                                @Html.Partial("_ScopeListItem", scope)
                            }
                        </ul>
                    </div>
                }

                @if (Model.ResourceScopes.Any())
                {
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <span class="glyphicon glyphicon-tasks"></span>
                            @sr["Application Access"]
                        </div>
                        <ul class="list-group">
                            @foreach (var scope in Model.ResourceScopes)
                            {
                                @Html.Partial("_ScopeListItem", scope)
                            }
                        </ul>
                    </div>
                }

                @if (Model.AllowRememberConsent)
                {
                    <div class="consent-remember">
                        <label>
                            <input class="consent-scopecheck" asp-for="RememberConsent" />
                            <strong>@sr["Remember My Decision"]</strong>
                        </label>
                    </div>
                }
                <div class="consent-buttons">
                    <button name="button" value="yes" class="btn btn-primary" autofocus data-enabled-text='@sr["Yes, Allow"]' data-disabled-text='@sr["Working..."]'>@sr["Yes, Allow"]</button>
                    <button name="button" value="no" class="btn" data-enabled-text='@sr["No, Do Not Allow"]' data-disabled-text='@sr["Working..."]'>@sr["No, Do Not Allow"]</button>
                    @if (Model.ClientUrl != null)
                    {
                        <a class="pull-right btn btn-default" target="_blank" href="@Model.ClientUrl">
                            <span class="glyphicon glyphicon-info-sign"></span>
                            <strong>@Model.ClientName</strong>
                        </a>
                    }
                </div>

            </form>
        </div>
    </div>
</div>
@section Scripts {
    @{await Html.RenderPartialAsync("_UnobtrusiveValidationScriptsPartial"); }
    <script src="~/cr/js/cloudscribe-validation-requiredwhen.min.js"></script>
    <script src="~/cr/js/jquery.validate.hooks.min.js"></script>
    <script src="~/cr/js/jqueryvaildation.submitonce-unobtrusive.min.js"></script>
}